﻿using System.Windows.Input;
using roysland.net.designpatterns.MVVM;
using roysland.net.xcom.editor.ViewModel;

namespace roysland.net.xcom.editor
{
    public sealed class MainWindowViewModel : WorkspacePresenterViewModel
    {
        
        private RelayCommand saveCommand;

        public MainWindowViewModel()
        {
            DisplayName = "X-COM UFO Defense Editor";
            InitializeData();
        }

        private void InitializeData()
        {
            ItemEditor = new ItemEditorViewModel();
            CraftEditor = new CraftEditorViewModel();
        }

        private ItemEditorViewModel itemEditor;
        public ItemEditorViewModel ItemEditor
        {
            get { return itemEditor; }
            set
            {
                if (value == itemEditor)
                    return;

                itemEditor = value;

                OnPropertyChanged("ItemEditor");
            }
        }

        private CraftEditorViewModel craftEditor;
        public CraftEditorViewModel CraftEditor
        {
            get { return craftEditor; }
            set
            {
                if (value == craftEditor)
                    return;

                craftEditor = value;

                OnPropertyChanged("CraftEditor");
            }
        }

        #region Commands
        #region Save
        public ICommand SaveCommand
        {
            get
            {
                if (saveCommand == null)
                {
                    saveCommand = new RelayCommand(
                        param => this.Save(),
                        param => this.CanSave
                        );
                }
                return saveCommand;
            }
        }

        public void Save()
        {
            ItemEditor.Save();
        }

        public bool CanSave
        {
            get { return true; }
        }
        #endregion
        #endregion
    }
}
